#include "PauseMenu.h"


PauseMenu::PauseMenu() {
}


PauseMenu::~PauseMenu() {
}


void PauseMenu::Initialize(sf::RenderWindow* window) {
	m_renderWindow = window;

	PauseTexture.loadFromFile("bilder/Pause/Pause.png");
	PauseSprite.setTexture(PauseTexture);

	ContinueTexture.loadFromFile("bilder/Pause/continue.png");
	ContinueSprite.setTexture(ContinueTexture);
	ContinueSprite.setOrigin(ContinueTexture.getSize().x/4, ContinueTexture.getSize().y/2);
	ContinueSprite.setPosition(PauseTexture.getSize().x/2, 222);


	OptionsTexture.loadFromFile("bilder/Pause/options.png");
	OptionsSprite.setTexture(OptionsTexture);
	OptionsSprite.setOrigin(OptionsTexture.getSize().x/4, OptionsTexture.getSize().y/2);
	OptionsSprite.setPosition(PauseTexture.getSize().x/2, 282);
	
	QuitTexture.loadFromFile("bilder/Pause/Quit.png");
	QuitSprite.setTexture(QuitTexture);
	QuitSprite.setOrigin(QuitTexture.getSize().x/4, QuitTexture.getSize().y/2);
	QuitSprite.setPosition(PauseTexture.getSize().x/2, 342);


	QuitToDesktopTexture.loadFromFile("bilder/Pause/QuittoDesktop.png");
	QuitToDesktopSprite.setTexture(QuitToDesktopTexture);
	QuitToDesktopSprite.setOrigin(QuitToDesktopTexture.getSize().x/4, QuitToDesktopTexture.getSize().y/2);
	QuitToDesktopSprite.setPosition(PauseTexture.getSize().x/2, 402);

	_quit = false;
	_continue = 2;
	

}

void PauseMenu::Update(sf::Vector2i mousePos, sf::RenderWindow* window) {
	m_mousePos = mousePos;
	m_renderWindow = window;


	m_renderWindow->draw(PauseSprite);

	// If in continue
	//if (m_mousePos.x > ContinueSprite.getPosition().x && m_mousePos.x < ContinueSprite.getPosition().x + ContinueTexture.getSize().x/2 && m_mousePos.y < ContinueSprite.getPosition().y + ContinueTexture.getSize().y && m_mousePos.y > ContinueSprite.getPosition().y) {
	if (m_mousePos.x > ContinueSprite.getPosition().x - ContinueTexture.getSize().x/4 && m_mousePos.x < ContinueSprite.getPosition().x + ContinueTexture.getSize().x/4 && m_mousePos.y < ContinueSprite.getPosition().y + ContinueTexture.getSize().y && m_mousePos.y > ContinueSprite.getPosition().y) {
		ContinueSprite.setTextureRect(sf::IntRect(232,0,232,62));
	} else {
		ContinueSprite.setTextureRect(sf::IntRect(0,0,232,62));
	}
	m_renderWindow->draw(ContinueSprite);


	if (m_mousePos.x > OptionsSprite.getPosition().x - OptionsTexture.getSize().x/4 && m_mousePos.x < OptionsSprite.getPosition().x + OptionsTexture.getSize().x/4 && m_mousePos.y < OptionsSprite.getPosition().y + OptionsTexture.getSize().y && m_mousePos.y > OptionsSprite.getPosition().y) {
		OptionsSprite.setTextureRect(sf::IntRect(181,0,181,41));
	}  else {
		OptionsSprite.setTextureRect(sf::IntRect(0,0,181,41));
	}
	m_renderWindow->draw(OptionsSprite);



	if (m_mousePos.x > QuitSprite.getPosition().x - QuitTexture.getSize().x/4 && m_mousePos.x < QuitSprite.getPosition().x + QuitTexture.getSize().x/4 && m_mousePos.y < QuitSprite.getPosition().y + QuitTexture.getSize().y && m_mousePos.y > QuitSprite.getPosition().y) {
		//QuitSprite.setTextureRect(sf::IntRect(122,0,122,46));
		QuitSprite.setTextureRect(sf::IntRect(121,0,121,46));
		//139.5,0,139.5,46
	}  else {
		//QuitSprite.setTextureRect(sf::IntRect(0,0,122,46));
		QuitSprite.setTextureRect(sf::IntRect(0,0,121,46));
	}
	m_renderWindow->draw(QuitSprite);


	if (m_mousePos.x > QuitToDesktopSprite.getPosition().x - QuitToDesktopTexture.getSize().x/4 && m_mousePos.x < QuitToDesktopSprite.getPosition().x + QuitToDesktopTexture.getSize().x/4 && m_mousePos.y < QuitToDesktopSprite.getPosition().y + QuitToDesktopTexture.getSize().y && m_mousePos.y > QuitToDesktopSprite.getPosition().y) {
		QuitToDesktopSprite.setTextureRect(sf::IntRect(389,0,389,67));
		if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
			window->close();
			_quit = true;
		}
	}  else {
		QuitToDesktopSprite.setTextureRect(sf::IntRect(0,0,389,67));
	}
	m_renderWindow->draw(QuitToDesktopSprite);


}

void PauseMenu::Cleanup() {

}

bool PauseMenu::QuitGame() {
	return _quit;
}

int PauseMenu::ChangeGame() {
	if (m_mousePos.x > ContinueSprite.getPosition().x - ContinueTexture.getSize().x/4 && m_mousePos.x < ContinueSprite.getPosition().x + ContinueTexture.getSize().x/4 && m_mousePos.y < ContinueSprite.getPosition().y + ContinueTexture.getSize().y && m_mousePos.y > ContinueSprite.getPosition().y) {
		if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
			_continue = 1;
			return _continue;
		}
	 } else if(m_mousePos.x > QuitSprite.getPosition().x - QuitTexture.getSize().x/4 && m_mousePos.x < QuitSprite.getPosition().x + QuitTexture.getSize().x/4 && m_mousePos.y < QuitSprite.getPosition().y + QuitTexture.getSize().y && m_mousePos.y > QuitSprite.getPosition().y) {
		 if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
			 _continue = 0;
			 return _continue;
		 }
	} else {
		return 2;
	 }
}